package com.chx.controller;

import com.chx.dto.StockInOrderDto;
import com.chx.dto.StockInOrderPageQueryDto;
import com.chx.result.PageResult;
import com.chx.result.Result;
import com.chx.service.StockInOrderService;
import com.chx.vo.StockInOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author cp-月入过万
 * @Date 2025/5/31
 * 入库订单相关接口
 */
@RestController
@RequestMapping("/admin/stock-in-order")
@Api(tags = "入库订单相关接口")
@Slf4j
public class StockInOrderController {
    @Autowired
    private StockInOrderService stockInOrderService;

    /**
     * 新增入库订单
     */
    @ApiOperation(value = "新增入库订单")
    @PostMapping
    public Result<String> save(@RequestBody StockInOrderDto stockInOrderDto) {
        log.info("新增入库订单：{}", stockInOrderDto);
        stockInOrderService.save(stockInOrderDto);
        return Result.success();
    }

    /**
     * 修改入库订单
     */
    @ApiOperation(value = "修改入库订单")
    @PutMapping
    public Result<String> update(@RequestBody StockInOrderDto stockInOrderDto) {
        log.info("修改入库订单：{}", stockInOrderDto);
        stockInOrderService.update(stockInOrderDto);
        return Result.success();
    }
    /**
     * 审核订单状态
     */
    @ApiOperation(value = "审核订单状态")
    @PutMapping("/status/{id}")
    public Result<String> updateStatus(@PathVariable Long id) {
        log.info("审核订单状态：{}", id);
        stockInOrderService.updateStatus(id);
        return Result.success();
    }
    /**
     * 提交入库订单
     */
    @ApiOperation(value = "提交入库订单")
    @PostMapping("/status/{id}")
    public Result<String> commit(@PathVariable Long id) {
        log.info("提交入库订单：{}", id);
        stockInOrderService.commit(id);
        return Result.success();
    }
    /**
     * 根据id查询入库订单
     */
    @ApiOperation(value = "根据id查询入库订单")
    @GetMapping("/{id}")
    public Result<StockInOrderVo> getById(@PathVariable Long id) {
        log.info("根据id查询入库订单：{}", id);
        StockInOrderVo stockInOrderVo = stockInOrderService.getById(id);
        return Result.success(stockInOrderVo);
    }
    /**
     * 分页查询入库订单
     */
    @ApiOperation(value = "分页查询入库订单")
    @GetMapping("/page")
    public Result<PageResult> page(StockInOrderPageQueryDto stockInOrderPageQueryDto) {
        log.info("分页查询入库订单：{}", stockInOrderPageQueryDto);
        PageResult pageResult = stockInOrderService.page(stockInOrderPageQueryDto);
        return Result.success(pageResult);
    }
}
